<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详细内容</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">
    <link rel="stylesheet" href="${assets}/plugins/ztree/zTreeStyle/metro.css" type="text/css">
    <!--[if IE 8]>
	<link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>
	<![endif]-->
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${assets}/js/jquery.serializejson.js"></script>
    <script src="${assets}/plugins/ztree/jquery.ztree.all-3.5.min.js"></script>

    <script type="text/javascript">
        var setting = {

            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            },

            data: {
                simpleData: {
                    enable: true
                }
            },
            callback: {
                beforeClick: beforeClick,
                onCheck: onCheck,
//                onClick: onClick
            }
        };


        var zNodes = ${menuList};

        function setCheck() {
            var zTree = $.fn.zTree.getZTreeObj("menuTree");
            console.log(zTree);
        }
        function beforeClick(treeId, treeNode, clickFlag) {
            var zTree = $.fn.zTree.getZTreeObj("menuTree");
            zTree.checkNode(treeNode, !treeNode.checked, null, true);
            return false;
        }

        $(document).ready(function () {
            $.fn.zTree.init($("#menuTree"), setting, zNodes);
            setCheck();
        });
        function onCheck(e, treeId, treeNode) {

            $("#parentId").val(treeNode.id);
            $("#parentName").val(treeNode.name);

        }


        //-->
    </script>


    <script>

        $(document).ready(function () {

            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    type: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    name: {
                        validators: {
                            notEmpty: true
                        }
                    },
                    perms: {
                        validators: {
                            notEmpty: true
                        }
                    }
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();

                var _url = "";
                if ($("#menuId").val() == null || $("#menuId").val() == '') {
                    _url = '${URL_SYS_MENU_LIST_ADD}';
                } else {
                    _url = '${URL_SYS_MENU_LIST_UPDATE}';
                }

                $.ajax({
                    url: _url,
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    error: function (data) {
                        alert('error');
                    },
                    success: function (data) {
                        closeFrame();
                    }
                });

            });
        });
        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }
    </script>
</head>
<body style="width: 98%;height:560px;">
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" id="menuId" name="menuId" value="${entity.menuId}"/>
    <input type="hidden" id="parentId" name="parentId" value="${entity.parentId}"/>
    <div class="clearfix">
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">类别${entity.type == 0 ? 1:2}：</label>
            <div class="col-sm-8">
                <select id="type" name="type" class="form-control">
                    <option value="0" ${entity.type == 0 ? 'selected' : ''} >目录</option>
                    <option value="1" ${entity.type == 1 ? 'selected' : ''}>菜单</option>
                    <option value="2" ${entity.type == 2 ? 'selected' : ''}>按钮</option>
                </select>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">菜单名称</label>
            <div class="col-sm-8">
                <input type="text" id="name" name="name" class="form-control" value="${entity.name}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">菜单URL</label>
            <div class="col-sm-8">
                <input type="text" id="url" name="url" class="form-control" value="${entity.url}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">授权标志</label>
            <div class="col-sm-8">
                <input type="text" id="perms" name="perms" class="form-control" value="${entity.perms}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">上级菜单</label>
            <div class="col-sm-8">
                <input type="text" id="parentName" name="parentName" class="form-control" value="${entity.parentName}"
                       readonly>
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">图标</label>
            <div class="col-sm-8">
                <input type="text" id="icon" name="icon" class="form-control" value="${entity.icon}">
            </div>
        </div>
        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">顺序</label>
            <div class="col-sm-8">
                <input type="text" id="orderNum" name="orderNum" class="form-control" value="${entity.orderNum}">
            </div>
        </div>

        <div class="form-group col-sm-6">
            <label class="col-sm-4 control-label">选择上级菜单</label>
            <div class="col-sm-8">
                <ul id="menuTree" class="ztree"></ul>
            </div>
        </div>

        <div class="modal-footer" style="text-align: center;padding-bottom:70px; ">
            <button type="button" class="btn btn-default" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">
                关闭
            </button>
            <button type="submit" class="btn btn-primary">保存</button>
        </div>
    </div>
</form>
</body>
</html>